#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QPainter>
#include <QImage>
#include <QDebug>
#include <QTimer>
#include <QtMultimedia/QMediaPlayer>
#include <QTcpServer>
#include <QTcpSocket>

#include "car.h"
#include "createmap.h"
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    void readMap();

    void keyPressEvent(QKeyEvent *ev);
    void keyReleaseEvent(QKeyEvent *ev);
    void paintEvent(QPaintEvent *);
    void mousePressEvent(QMouseEvent *event);

    void initParam();

    int sec;

    QTimer *m_timer;
    QTimer *show_timer;
    Car car;
    vector<IPoint> savePath;

    bool angle_mode;

    bool start;

    QImage back;

    QPointF points[5];

    bool longAcc;
    bool showLast;
    unsigned int showTimes;

    char backImage[200];
    char mapImage[200];
    double facc,max_speed;

    int Iwidth,Iheight;

    CreateMap createMap;

    void server_recv(char recvBuf[]);

private slots:
    void on_car_clicked();
    void drawCar();

    void on_car_3_clicked();

    void start_show();

    void on_car_4_clicked();

private:
    Ui::MainWindow *ui;
    QMediaPlayer *song;

    QTcpSocket  *tcpSocket;//通信套接字

    int recvLen;
    char recvBuf[64];
    double last_ang;
};

#endif // MAINWINDOW_H
